package logic

import (
	"context"
	"errors"
	"zg2_zy/zy6_company/companyRpc/models"

	"zg2_zy/zy6_company/companyRpc/company"
	"zg2_zy/zy6_company/companyRpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelJobLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelJobLogic {
	return &DelJobLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelJobLogic) DelJob(in *company.DelJobRequest) (*company.DelJobResponse, error) {
	// todo: add your logic here and delete this line

	var err error
	var c models.Company
	c.ID = uint(in.Id)

	if err = c.GetJobById(); err != nil {
		return nil, errors.New("获取失败")
	}

	if c.ID == 0 {
		return nil, errors.New("该职位不存在")
	}

	if err = c.DelById(); err != nil {
		return nil, errors.New("删除失败")
	}
	return &company.DelJobResponse{}, nil
}
